/*    This file is part of rls.
 *
 *    Rls is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU Lesser General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    Rls is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public License
 *    along with rls.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef RLSP_H
#define RLSP_H

/*
Include:
something with size_t
#include <rid.h>
#include <stdint.h>

#include <unfy/unfy.h>

#include <rls/rls.h>

#include <rls/rlsp.h>
*/

#ifndef STYLE_9
#include <rls/rls.h>
#endif

typedef enum {
	RLSP_RULE,
	RLSP_ROPEN,
	RLSP_RCLOSE,
	RLSP_RNIL,
	RLSP_SNIL,
	RLSP_SOPEN
} Rlsp_type;

typedef void (*Rlsp_dat_print)(void *extra);

typedef struct Rlsp_srlz Rlsp_srlz;

typedef size_t (*Rlsp_len)(const Rls_rule *rule, void *extra);
typedef size_t (*Rlsp_write)(const Rls_rule *rule, unsigned char *buf,
			     void *extra);
typedef int (*Rlsp_deser)(Rls_rule *rule, const unsigned char *buf,
			  size_t *pos, void *extra);
typedef const char *
(*Rlsp_deserable)(const unsigned char *buf, size_t *pos,
		  size_t max, void *extra);

struct Rlsp_srlz {
	Rls_dat_free dat_free;
	Rlsp_len len;
	Rlsp_write write;
	Rlsp_deser deser;
	Rlsp_deserable deserable;
};

/* rule */

void
rlsp_rule_print(const Rls_rule *rule, Rlsp_dat_print dat_print);

size_t
rlsp_rule_len(const Rls_rule *rule, Rlsp_srlz *srlz, void *extra);

size_t
rlsp_rule_write(const Rls_rule *rules, unsigned char *buf,
		Rlsp_srlz *srlz, void *extra);

int
rlsp_rule_ser(const Rls_rule *rules, unsigned char **buf, size_t *size,
	      size_t *pos, Rlsp_srlz *srlz, void *extra);

int
rlsp_rule_deser(Rls_rule **rules, const unsigned char *buf, size_t *pos,
		Rlsp_srlz *srlz, void *extra, Rls_recycle *rec);

const char *
rlsp_rule_deserable(const unsigned char *buf, size_t *pos,
		    const size_t max, Rlsp_srlz *srlz, void *extra);

/* srch */

void
rlsp_srch_print(const Rls_srch *srch, int level);

size_t
rlsp_srch_len(const Rls_srch *srch);

size_t
rlsp_srch_write(const Rls_srch *srch, unsigned char *buf);

int
rlsp_srch_ser(const Rls_srch *srch, unsigned char **buf,
	      size_t *size, size_t *pos);

const char *
rlsp_srch_deser(Rls_srch **srch, const unsigned char *buf, size_t *pos,
		Rls_rule *rules, Rls_bend bend, void *extra, Rls_recycle *rec);

const char *
rlsp_srch_deserable(const unsigned char *buf, size_t *pos, const size_t max);

#endif
